<template>
	<view class="tabbar x-bc">
		<view class="x-f" v-for="(tabbar,index) in category_a" :key="index">
			<view class="cate_name" @tap="clickTab(index)">{{tabbar.cate_name}}</view>
			<image :src="img"></image>
		</view>
	</view>
</template>

<script>
	export default {
		name:"select",
		props: {
			category_a: {
				type: Array,
				default: ()=>[]
			},
			img: {
				type: String,
				default: ''
			},
			// 当前活动tab的索引
			current: {
				type: [Number, String],
				default: 0
			},
		},
		data() {
			return {
				currentIndex: this.current,
			};
		},
		methods: {
			clickTab(index) {
				// 点击当前活动tab，不触发事件
				if(index == this.currentIndex) return ;
				// 发送事件给父组件
				this.$emit('change', index);
			},
		}
	}
</script>

<style lang="scss" scoped>
	.tabbar {
		margin: 16rpx 0;
		border-radius: 16rpx;
		background: #fff;
		padding: 24rpx;
		.cate_name {
			color: #000;
			padding-right: 10rpx;
		}
		image {
			width: 20rpx;
			height: 20rpx;
		}
	}
</style>
